﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BlackBird.Models;

namespace BlackBird.DataAccess
{
	public class CommonDataAccess
	{
		/// <summary>
		/// Get SupportTypes form Event_type table
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		public static SupportTypes GetSupportTypesById(int id)
		{
			var item = GlobalObjectBuffer.AllEventTypes.FirstOrDefault(v => v.idEvent_type == id).Type;

			return (SupportTypes)Enum.Parse(typeof(SupportTypes), item);
		}


		/// <summary>
		/// Get SuportTypeStatus Form Status table
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		public static SupportTypeStatus GetSupportTypeStatusById(int id)
		{
			var item = GlobalObjectBuffer.allStatus.FirstOrDefault(v => v.idStatus == id).StatusType;

			return (SupportTypeStatus)Enum.Parse(typeof(SupportTypeStatus), item);

		}

		/// <summary>
		/// 通过SupportTypeStatus 获得数据库中的ID
		/// </summary>
		/// <param name="type"></param>
		/// <returns></returns>
		public static int GetSupportTypeStatusId(SupportTypeStatus type)
		{
			var id = GlobalObjectBuffer.allStatus.FirstOrDefault(v => String.Compare( v.StatusType,type.ToString(),true) == 0 ).idStatus;

			return id;
		}
	}
}